import da from "element-ui/src/locale/lang/da";

var state = {
    IsRefresh:true,      //判断页面是否刷新
    Authorization:sessionStorage.getItem('Authorization')?sessionStorage.getItem('Authorization'):'',
    menuInfo:sessionStorage.getItem('menuInfo')?JSON.parse(sessionStorage.getItem('menuInfo')):[],
    userInfo:sessionStorage.getItem('userInfo')?JSON.parse(sessionStorage.getItem('userInfo')):[]
};

var actions = {
    setNoRefresh({commit}) {
        commit('setNoRefresh')
    },
    loginSuccess({commit},data) {
        commit('loginSuccess',data)
    },
    getAside({commit},data){
        commit('getAside',data)
    },
    loginEdit({commit}) {
        commit('loginEdit')
    }
};

var mutations ={
    setNoRefresh(state){
        state.IsRefresh = false; //设置不刷新
    },
    loginSuccess(state,data){     //登录成功，存储信息到浏览器
        state.userInfo = data.userInfo;
        state.Authorization = data.Authorization;
        sessionStorage.setItem('Authorization',state.Authorization);
        sessionStorage.setItem('userInfo',JSON.stringify(state.userInfo));
    },
    getAside(state,data){       //获取侧边栏
        state.menuInfo = data.menuInfo;
        sessionStorage.setItem('menuInfo',JSON.stringify(state.menuInfo));
    },
    loginEdit(state){      //注销
        state.menuInfo = [];
        state.userInfo = [];
        state.Authorization = '';
        sessionStorage.removeItem('Authorization');
        sessionStorage.removeItem('menuInfo');
        sessionStorage.removeItem('userInfo');
    }
};

var getters = {
    getRefresh(state){
        return state.IsRefresh
    },
    getMenuInfo(state){
        return [...state.menuInfo]
    },
    getUserInfo(state){
        return {...state.userInfo}
    }
};

export default {
    state,
    getters,
    actions,
    mutations
}
